home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / maniach.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  3KB  |  137 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12.  
  13. static unsigned char from_main,from_mcu;
  14. static int mcu_sent = 0,main_sent = 0;
  15.  
  16.  
  17. /***************************************************************************
  18.  
  19.  Mania Challenge 68705 protection interface
  20.  
  21.  The following is ENTIRELY GUESSWORK!!!
  22.  
  23. ***************************************************************************/
  24.  
  25. static unsigned char portA_in,portA_out,ddrA;
  26.  
  27. READ_HANDLER( maniach_68705_portA_r )
  28. {
  29. //logerror("%04x: 68705 port A read %02x\n",cpu_get_pc(),portA_in);
  30.     return (portA_out & ddrA) | (portA_in & ~ddrA);
  31. }
  32.  
  33. WRITE_HANDLER( maniach_68705_portA_w )
  34. {
  35. //logerror("%04x: 68705 port A write %02x\n",cpu_get_pc(),data);
  36.     portA_out = data;
  37. }
  38.  
  39. WRITE_HANDLER( maniach_68705_ddrA_w )
  40. {
  41.     ddrA = data;
  42. }
  43.  
  44.  
  45.  
  46. /*
  47.  *  Port B connections:
  48.  *
  49.  *  all bits are logical 1 when read (+5V pullup)
  50.  *
  51.  *  1   W  when 1->0, enables latch which brings the command from main CPU (read from port A)
  52.  *  2   W  when 0->1, copies port A to the latch for the main CPU
  53.  */
  54.  
  55. static unsigned char portB_in,portB_out,ddrB;
  56.  
  57. READ_HANDLER( maniach_68705_portB_r )
  58. {
  59.     return (portB_out & ddrB) | (portB_in & ~ddrB);
  60. }
  61.  
  62. WRITE_HANDLER( maniach_68705_portB_w )
  63. {
  64. //logerror("%04x: 68705 port B write %02x\n",cpu_get_pc(),data);
  65.  
  66.     if ((ddrB & 0x02) && (~data & 0x02) && (portB_out & 0x02))
  67.     {
  68.         portA_in = from_main;
  69.         main_sent = 0;
  70. //logerror("read command %02x from main cpu\n",portA_in);
  71.     }
  72.     if ((ddrB & 0x04) && (data & 0x04) && (~portB_out & 0x04))
  73.     {
  74. //logerror("send command %02x to main cpu\n",portA_out);
  75.         from_mcu = portA_out;
  76.         mcu_sent = 1;
  77.     }
  78.  
  79.     portB_out = data;
  80. }
  81.  
  82. WRITE_HANDLER( maniach_68705_ddrB_w )
  83. {
  84.     ddrB = data;
  85. }
  86.  
  87.  
  88. static unsigned char portC_in,portC_out,ddrC;
  89.  
  90. READ_HANDLER( maniach_68705_portC_r )
  91. {
  92.     portC_in = 0;
  93.     if (main_sent) portC_in |= 0x01;
  94.     if (!mcu_sent) portC_in |= 0x02;
  95. //logerror("%04x: 68705 port C read %02x\n",cpu_get_pc(),portC_in);
  96.     return (portC_out & ddrC) | (portC_in & ~ddrC);
  97. }
  98.  
  99. WRITE_HANDLER( maniach_68705_portC_w )
  100. {
  101. //logerror("%04x: 68705 port C write %02x\n",cpu_get_pc(),data);
  102.     portC_out = data;
  103. }
  104.  
  105. WRITE_HANDLER( maniach_68705_ddrC_w )
  106. {
  107.     ddrC = data;
  108. }
  109.  
  110.  
  111. WRITE_HANDLER( maniach_mcu_w )
  112. {
  113. //logerror("%04x: 3040_w %02x\n",cpu_get_pc(),data);
  114.     from_main = data;
  115.     main_sent = 1;
  116. }
  117.  
  118. READ_HANDLER( maniach_mcu_r )
  119. {
  120. //logerror("%04x: 3040_r %02x\n",cpu_get_pc(),from_mcu);
  121.     mcu_sent = 0;
  122.     return from_mcu;
  123. }
  124.  
  125. READ_HANDLER( maniach_mcu_status_r )
  126. {
  127.     int res = 0;
  128.  
  129.     /* bit 0 = when 0, mcu has sent data to the main cpu */
  130.     /* bit 1 = when 1, mcu is ready to receive data from main cpu */
  131. //logerror("%04x: 3041_r\n",cpu_get_pc());
  132.     if (!mcu_sent) res |= 0x01;
  133.     if (!main_sent) res |= 0x02;
  134.  
  135.     return res;
  136. }
  137.